//
//  ZXbottomView.m
//  JJHW_coreData
//
//  Created by lizhenqiang on 16/5/8.
//  Copyright © 2016年 HFKJ_LZQ. All rights reserved.
//

#import "ZXbottomView.h"
#import "SplashObj.h"
@implementation ZXbottomView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(void)setViewData:(NSMutableArray *)array andTitle:(NSString *)title
{
    if (self.tableview) {
        [self.tableview removeFromSuperview];
        self.tableview = nil;
    }
    self.objArray = array;
    if (array.count>5) {
        self.isScrollFlag = YES;
    }
    else
    {
        self.isScrollFlag = NO;
    }
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake((DeviceWidth-self.myHeight)/2, (self.myHeight-DeviceWidth)/2, self.myHeight, DeviceWidth)];
    self.tableview.scrollEnabled = self.isScrollFlag;
    self.tableview.transform = CGAffineTransformMakeRotation(-M_PI/2);
    self.tableview.separatorStyle = UITableViewCellSeparatorStyleNone;//没有线
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    self.tableview.showsHorizontalScrollIndicator = NO;
    self.tableview.showsVerticalScrollIndicator = NO;
    self.tableview.backgroundColor = NavBarBJColor;
    [self.tableview registerNib:[UINib nibWithNibName:@"bottomViewCell" bundle:nil] forCellReuseIdentifier:@"bottomViewCell"];
    //    [self addSubview:_allBtn];
    [self addSubview:self.tableview];
    [self.tableview reloadData];
    self.selectedRow = 0;
    NSIndexPath *path = [NSIndexPath indexPathForRow:0 inSection:0];
    [self.tableview selectRowAtIndexPath:path animated:YES scrollPosition:UITableViewScrollPositionNone];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.objArray.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//    SplashObj *obj = self.objArray[indexPath.row];
    if (self.isScrollFlag) { //数据比较多
        return kScaleFrom_iphone6_Desgin(75);
    }
    else
    {//不能滑动 数据比较少
        if (self.objArray.count>0) {
            
            return DeviceWidth/(self.objArray.count);
        }
    }
    
    return 0;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    bottomViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"bottomViewCell"];
    cell.transform = CGAffineTransformMakeRotation(M_PI/2);
    SplashObj *obj = self.objArray[indexPath.row];
    cell.nameLabel.text = obj.name;
    cell.backgroundColor = TabBarBjNormalColor;
//    cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame];
//    cell.selectedBackgroundView.backgroundColor = TabBarBjSelectColor;
    
    
    if (self.isScrollFlag) { //数据比较多
        CGFloat width = (kScaleFrom_iphone6_Desgin(75)-obj.nameWidth+20)/2.0;
        cell.nameLabel.frame = CGRectMake(width, 0, obj.nameWidth-20, self.myHeight);
        
    }
    else
    {//不能滑动 数据比较少
        if (self.objArray.count>0) {
            
            CGFloat width = (DeviceWidth/self.objArray.count-obj.nameWidth+20)/2;
            cell.nameLabel.frame = CGRectMake(width, 0, obj.nameWidth-20, self.myHeight);
        }
    }
    
    
    //    if (indexPath.row == 0) {
    //
    //        cell.nameLabel.frame = CGRectMake(12, 0, obj.nameWidth-24, _myHeight);
    //    }
    //    else
    //    {
    //        if (_isScrollFlag) { //数据比较多
    //
    //            cell.nameLabel.frame = CGRectMake(10, 0, obj.nameWidth-20, _myHeight);
    //        }
    //        else
    //        {//不能滑动 数据比较少
    //            if (_objArray.count>0) {
    //
    //                CGFloat width = (DeviceWidth-60)/(_objArray.count-1);
    //                if (width>obj.nameWidth) {
    //
    //                   cell.nameLabel.frame = CGRectMake((width-(obj.nameWidth-20))/2, 0, obj.nameWidth-20, _myHeight);
    //                }
    //                else
    //                {
    //                    cell.nameLabel.frame = CGRectMake(5, 0, width-10, _myHeight);
    //                }
    //            }
    //        }
    //    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
    
    return nil;
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    CDLog(@"去相应的子菜单");
}

@end
